const mainKey="p2pMapParams"

function initMapParams(){
	let p2pMapParams= localStorage.getItem(mainKey)
	if(p2pMapParams==null||p2pMapParams==undefined||p2pMapParams.trim()==""){
		p2pMapParams={"version":"1.0"}
		localStorage.setItem(mainKey,JSON.stringify(p2pMapParams))
	}
}

initMapParams()

function putParam(key,value){
	let p2pMapParams= localStorage.getItem(mainKey)
	let data = new Map(Object.entries(JSON.parse(p2pMapParams)))
	data.set(key,value)
	let obj = {};
	data.forEach((value, key) => {
	    obj[key] = value;
	});

	// console.log(data)
	localStorage.setItem(mainKey,JSON.stringify(obj))
}

function getParam(key){
	let p2pMapParams= localStorage.getItem(mainKey)
	let data = new Map(Object.entries(JSON.parse(p2pMapParams)))
	return data.get(key)
}

function getLocationUri(){
	// window.location.pathname.lastIndexOf("/")
	// console.log(window.location.pathname)
	
	// console.log(window.location.pathname.substring(window.location.pathname.lastIndexOf("/")+1))
	
	return window.location.pathname.substring(window.location.pathname.lastIndexOf("/")+1)
}